<!doctype html>
<html>
<head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
    <title>岗位列表</title>
    <script src="/webjars/miniui/boot.js" type="text/javascript"></script>
    <script src="/static/js/common/common.js" type="text/javascript"></script>
    <link href="/static/css/resource.css" rel="stylesheet" type="text/css" />
    <style type="text/css">
        body {
            margin:0;
            padding:0;
            border:0;
            width:100%;
            height:100%;
            overflow:hidden;
        }
    </style>
</head>
<body>
<div class="role-search">
    <div class="mini-toolbar" style="padding:2px;border-top:0;border-left:0;border-right:0;">
        <table>
            <tr>
                <td style="width: 100%;">
                    <a class="mini-button" iconCls="fa fa-plus" onclick="addPosition()" plain="true">新增</a>
                </td>
                <td style="white-space: nowrap;text-align:right;">
                    <input class="mini-textbox" id="key" class="mini-textbox" emptyText="岗位名称" onenter="onKeyEnter" />
                    <a class="mini-button" plain="true" iconCls="fa fa-search" plain="true" onclick="search()">查询</a>
                </td>
            </tr>
        </table>
    </div>
</div>

<!--撑满页面-->
<div class="mini-fit">
    <div id="datagrid1" class="mini-datagrid" style="width: 100%; height: 100%;" ajaxType="get" multiSelect="false"
         sizeList="[20,50,100]" pageSize="50" virtualScroll="false" showLoading="true"
         idField="id" url="/basic/position/getPositionList">
        <input name="orgid" class="mini-hidden" style="width: 100%;" readonly />
        <div property="columns">
            <div type="indexcolumn" headerAlign="center">序号</div>
            <div name="id" field="id" align="center" headerAlign="center" allowSort="false">岗位编号</div>
            <div name="name" field="name" align="center" headerAlign="center" allowSort="false">岗位名称</div>
            <div name="stat" field="stat" align="center" renderer="onStateRenderer" headerAlign="center" allowSort="false">岗位状态</div>
            <div name="action" headerAlign="center" align="center" renderer="onActionRenderer" cellStyle="padding:0;"
                 allowSort="false" multiSelect="false">操作
            </div>
        </div>
    </div>
</div>
<script type="text/javascript">
    mini.parse();
    var grid = mini.get("datagrid1");
    var flag = mini.get("flag");
    grid.load();

    //渲染列中按钮
    function onActionRenderer(e) {
        var s = '';
        s += '&nbsp;<a class="mini-button mini-button-primary"  onclick="editposition()" >&nbsp;编辑&nbsp;</a>&nbsp';
        s += '&nbsp;<a class="mini-button mini-button-danger"   onclick="delposition();" >&nbsp;删除&nbsp;</a>&nbsp';
        return s;
    }

    //新增岗位
    function addPosition() {
        var data = {stat: 1};
        if (data) {
            showPositionWindow(data, 1);
        }
    }

    //修改用户
    function editposition() {
        var row = grid.getSelected();
        if (row) {
            showPositionWindow(row, 2);
        } else {
            mini.alert("请至少选择一条数据！");
        }
    }

    function showPositionWindow(row, flag) {
        commonEdit("/basic/position/edit?flag=" + flag, "岗位信息", row, 600, 500, true, false, true, callback);

        function callback() {
            grid.reload();
        }
    }

    function delposition() {
        var row = grid.getSelected();
        if (row) {
            commonRemove("/basic/position/delete/" + row.id, row, {_method: "delete"}, callback);

            function callback() {
                grid.reload();
            }
        } else {
            mini.alert("请至少选中一条记录");
        }
    }

    //查询
    function onKeyEnter(e) {
        search();
    }

    function search() {
        var key = mini.get("key").getValue();
        key = encodeURI(key);
        grid.load({key: key});
    }

    // 渲染授权状态
    function onStateRenderer(e) {
        var Statedata = [{id: -1, text: '禁用'}, {id: 0, text: '不存在'}, {id: 1, text: '启用'}];
        for (var i = 0, l = Statedata.length; i < l; i++) {
            var g = Statedata[i];
            if (g.id == e.value) return g.text;
        }
        return "其他";
    }
</script>
</body>
</html>